/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[InnerClass1.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package objectOriented;

/**
 * 普通内部类<br/>
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class InnerClass1 {

	private String name = "outer_class";

	static {
		System.out.println("outer_class static block");
	}

	{
		System.out.println("outer_class initial block");
	}

	public InnerClass1() {
		System.out.println("outer_class constructor");
	}

	/**
	 * 
	 * @author 不落的太阳(Sean Yang aka ShortPeace)
	 * @version 1.0
	 * @since jdk 1.8
	 *
	 */
	private class InnerClass {

		private String name = "inner_class";

		/**
		 * 此处的静态代码块是错误的,因为普通内部类相当于外部类中的一个属性[方法]<br/>
		 * 内部类中的属性和方法相当于局部变量,因此不能使用static关键字<br/>
		 * 
		 * static { System.out.println("inner_class static block"); }
		 */
		{
			System.out.println("inner_class initial block");
		}

		public InnerClass() {
			System.out.println("inner_class constructor");
		}

		public void method() {
			System.out.println("inner_class method2");
		}

		public void test() {
			System.out.println(name);
			System.out.println(this.name);
			System.out.println(InnerClass1.this.name);// 调用外部类的同名属性
		}
	}

	public void method() {
		System.out.println("outer_class method1");
	}

	public static void main(String[] args) {
		InnerClass1.InnerClass innerClass = new InnerClass1().new InnerClass();
		innerClass.method();
		innerClass.test();
	}
}
